#include "loadmapinstructiondelegate.h"
#include "../LoadMapInstructionView/loadmapinstructionview.h"
#include <QDebug>
#include "../../FtpManage/ftpmanage.h"
#include "../../CommunicateDelegate/filedata.h"
#include "instructionEnum.h"
#include "hmicommondefine.h"

extern FileData fileData;
extern FtpManage *ftpManage;
LoadMapInstructionDelegate::LoadMapInstructionDelegate(GlobalData *globalDataIn, QWidget *parent)
    : QWidget(parent)
{
    globalData=globalDataIn;
}

void LoadMapInstructionDelegate::initView()
{
    loadMapInstructionView->mapFileName = "";
    loadMapInstructionView->jmpLabel = "1";
    loadMapInstructionView->noteStr = "";
    loadMapInstructionView->instructionStr = "";
    if(globalData->isUseFtpOrNfs)
    {

        fileData.ftpOperateNum = EM_FTP_OPERATE_LOAD_MAP;
        ftpManage->getFileInDirectory(D_MAP_PATH,D_MAP_PATH);
    }
    else
    {
        fileData.ftpOperateNum = EM_FTP_OPERATE_CLOSE;
        qDebug() << "FtpManage Unopened!";
    }
}

void LoadMapInstructionDelegate::finishededitinstructionSlot()
{
    loadMapInstructionView->instructionStr = tr("LOAD_MAP ");
    loadMapInstructionView->instructionStr += loadMapInstructionView->mapFileName + ",";
    loadMapInstructionView->instructionStr += tr("JMP LB[") + loadMapInstructionView->jmpLabel + tr("]  ");
    loadMapInstructionView->instructionStr += tr("//") + loadMapInstructionView->noteStr;
    
    qDebug() << "finished Edit Load Map Instruction:" << loadMapInstructionView->instructionStr;
}

void LoadMapInstructionDelegate::cleanNote_slot()
{
    loadMapInstructionView->noteStr.clear();
}
